export default {
  namespaced: true,
  state: () => ({
    address: JSON.parse(uni.getStorageSync('address') || '{}'),
    token: uni.getStorageSync('token') || '',
    userInfo: JSON.parse(uni.getStorageSync('userInfo') || '{}'),
    redirectInfo: null
  }),
  mutations: {
    // 修改本地地址
    updateAddress(state, address){
      state.address = address
      this.commit('m_user/saveToStorage')
    },
    // 修改userInfo的值
    updateUserInfo(state, userInfo){
      state.userInfo = userInfo
      this.commit('m_user/saveUserInfoStorage')
    },
    // 修改token的值
    updateToken(state, token){
      state.token = token
      this.commit('m_user/saveTokenStorage')
    },
    // 修改redirectInfo的值
    updateRedirectInfo(state, info){
      state.redirectInfo = info
    },
    // 封装地址持久化插件
    saveToStorage(state){
      uni.setStorageSync('address', JSON.stringify(state.address))
    },
    // 封装userInfo持久化插件
    saveUserInfoStorage(state){
      uni.setStorageSync('userInfo', JSON.stringify(state.userInfo))
    },
    // 封装token持久化插件
    saveTokenStorage(state){
      uni.setStorageSync('token', state.token)
    }
  },
  getters: {
    longAddress(state){
     return state.address.provinceName + state.address.cityName + state.address.countyName + state.address.detailInfo
    }
  },
}